<?php

namespace App\Http\Controllers;

use App\Models\ArticleModel;
use App\Models\BannerModel;
use App\Models\MessageNotificationModel;

class IndexController extends Controller
{
    /**
     * Create a new AuthController instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:api', ['except' => []]);
    }

    /**
     * Get a JWT via given credentials.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function home()
    {

        $member_sub = response()->json(auth('api')->user());

        $member_list = $member_sub->original;

        $banner_list = BannerModel::where(['status'=>1])->select(['title','banner'])->orderBy('weight','desc')->get();

        $article_list = ArticleModel::where(['status'=>1])->select(['id','title','cover','type','title_content'])->orderBy('created_at','desc')->get();

        $message_count = MessageNotificationModel::where(['admin_id'=>$member_list['id']])->count();

        $data['message_count'] = $message_count;
        $data['banner_list'] = $banner_list;
        $data['article_list'] = $article_list;

        return response()->json(['code'=>'200','msg' => '请求成功','data'=>$data]);

    }

}
